//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.neurosky.thinkgear;

public class Detrend {
    private float a;
    private float[] b;
    private float[] c;
    private float[] d;
    private float[] e;
    private float f;
    private float g;
    private int h;
    private int i;

    public Detrend() {
    }

    public float[] removeLinearTrend(float[] var1) {
        this.i = var1.length;
        this.d = new float[this.i];
        this.e = new float[this.i];

        for(this.h = 0; this.h < this.i; ++this.h) {
            this.e[this.h] = (float)(this.h + 1);
        }

        this.f = (float)((double)(this.a(var1) * this.a(this.b(this.e)) - this.a(this.e) * this.a(this.a(this.e, var1))) / ((double)((float)this.i * this.a(this.b(this.e))) - Math.pow((double)this.a(this.e), 2.0D)));
        this.g = (float)((double)((float)this.i * this.a(this.a(this.e, var1)) - this.a(this.e) * this.a(var1)) / ((double)((float)this.i * this.a(this.b(this.e))) - Math.pow((double)this.a(this.e), 2.0D)));

        for(this.h = 0; this.h < this.i; ++this.h) {
            this.d[this.h] = (float)((double)var1[this.h] - ((double)this.f + (double)this.g * ((double)((float)this.h) + 1.0D)));
        }

        return this.d;
    }

    private float a(float[] var1) {
        this.a = 0.0F;

        for(int var2 = 0; var2 < var1.length; ++var2) {
            this.a += var1[var2];
        }

        return this.a;
    }

    private float[] a(float[] var1, float[] var2) {
        this.b = new float[var1.length];

        for(int var3 = 0; var3 < var1.length; ++var3) {
            this.b[var3] = var1[var3] * var2[var3];
        }

        return this.b;
    }

    private float[] b(float[] var1) {
        this.c = new float[var1.length];

        for(int var2 = 0; var2 < var1.length; ++var2) {
            this.c[var2] = (float)Math.pow((double)var1[var2], 2.0D);
        }

        return this.c;
    }
}
